﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:AgFx="clr-namespace:AgFx;assembly=AgFx" 
    xmlns:converters="clr-namespace:AgFx.Converters;assembly=AgFx"
    x:Class="NWSWeather.Sample.MainPage"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <converters:StringFormatConverter x:Key="StringFormatConverter"/>        
        <converters:VisibilityConverter x:Key="VisibilityConverter1" />
    </phone:PhoneApplicationPage.Resources>

    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource ResourceKey="PhoneFontSizeNormal"/>
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource ResourceKey="PhoneForegroundBrush"/>
    </phone:PhoneApplicationPage.Foreground>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent" d:DataContext="{d:DesignData /SampleData/WeatherForecastVmSampleData.xaml}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="5">
            <TextBlock x:Name="ApplicationTitle" Text="NWS Weather Sample" Style="{StaticResource PhoneTextNormalStyle}"/>
        </StackPanel>


        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="60" />                
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>


            <TextBox InputScope="Number" Height="77" x:Name="txtZipCode" Text="" VerticalAlignment="Top" Width="334" HorizontalAlignment="Left" />
            <Button Content="Go" Height="77" x:Name="btnAddZipCode" VerticalAlignment="Top" Width="103" Click="btnAddZipCode_Click" HorizontalAlignment="Right" />


            <Grid x:Name="info" Visibility="Collapsed" Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>
                <StackPanel Orientation="Horizontal" Grid.Row="0">
                    <TextBlock Text="{Binding ZipCodeInfo.City}" FontWeight="Bold"/>
                    <TextBlock Text="{Binding ZipCodeInfo.State}" FontWeight="Bold" Margin="5,0,0,0" HorizontalAlignment="Left" />
                </StackPanel>

                <Border Visibility="{Binding IsUpdating, Converter={StaticResource VisibilityConverter1}, ConverterParameter=!}" Grid.Row="1">
                    <StackPanel Orientation="Horizontal" Grid.Row="1" Visibility="{Binding Path=WeatherPeriods.Count, Converter={StaticResource VisibilityConverter1}}">
                        <TextBlock Text="Last Updated: "/>
                        <TextBlock Text="{Binding Path=LastUpdated, ConverterParameter=\{0:m\} \{0:t\}, Converter={StaticResource StringFormatConverter}}"/>
                        <HyperlinkButton Content="Refresh" x:Name="btnRefresh" Click="btnRefresh_Click"/>
                    </StackPanel>
                </Border>
                <TextBlock Text="Updating..." Visibility="{Binding Path=IsUpdating, Converter={StaticResource VisibilityConverter1}}" Grid.Row="1" />
            </Grid>
           

            <ScrollViewer HorizontalAlignment="Left" Margin="27,2,0,20"  Grid.Row="3" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" >
                <ItemsControl x:Name="forecast" ItemsSource="{Binding WeatherPeriods}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="1">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="60"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="60"/>
                                    <ColumnDefinition Width="60"/>
                                </Grid.ColumnDefinitions>
                                <Rectangle Width="60" Height="60" Fill="Silver" Grid.RowSpan="2"/>
                                <Image Width="60" Height="60" Stretch="UniformToFill" Source="{Binding WeatherImage}" Grid.RowSpan="2"  />
                                <TextBlock Margin="2,0,0,0" Text="{Binding Title}" FontWeight="Bold" d:LayoutOverrides="Height" Grid.Column="1"/>
                                <TextBlock Grid.Column="1"  Margin="2,0,0,0" HorizontalAlignment="Left" Text="{Binding Summary}" Grid.Row="1"  Width="233"/>
                                <TextBlock Grid.Column="2" Text="Temp:"/>
                                <TextBlock Grid.Column="3" Text="{Binding MaxTemperature, ConverterParameter=\{0\}°, Converter={StaticResource StringFormatConverter}}" Foreground="#FFE49A9A"  HorizontalAlignment="Right"/>
                                <TextBlock Grid.Column="3" Text="{Binding MinTemperature, ConverterParameter=\{0\}°, Converter={StaticResource StringFormatConverter}}" Foreground="#FFA6ABE9"  HorizontalAlignment="Right"/>
                                <TextBlock Grid.Column="2" Text="Precip:" Grid.Row="1" />
                                <TextBlock Grid.Column="3" Text="{Binding PrecipChancePercent, ConverterParameter=\{0\}%, Converter={StaticResource StringFormatConverter}}" Grid.Row="1" HorizontalAlignment="Right" />
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>